/*
 * Group 3, User Interface Programming II (vt11)
 * Pooya | Flora | Monica | Can
 */
package vical.model;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import vical.controller.EntryController;

/**
 * The model for a single date, it should include a dayModel and other
 * additional information for a day card.
 * 
 * @author Can
 * @author Flora
 */
public class DayCardModel {

    private int dayNumber;
    private int year;
    private int month;
    private ArrayList<Entry> entries;
    private DayType dayType;
    private List<String> categoriesFilter;
    private ArrayList<String> prioritiesFilter;

    /**
     * Each day should be specified by a type, and the
     * color of each day is defined by its type.
     */
    public enum DayType {

        RegularDay,
        Holiday,
        OtherDays
    }

    public DayCardModel(Calendar date, DayType type) {
        this.dayType = type;
        this.categoriesFilter = EntryController.getCategories();
        this.prioritiesFilter = EntryController.getPriorities();
        this.dayNumber = date.get(Calendar.DAY_OF_MONTH);
        this.month = date.get(Calendar.MONTH);
        this.year = date.get(Calendar.YEAR);

        entries = EntryController.LoadEntries(date);
    }

    public void updateEntries() {
        Calendar date = Calendar.getInstance();
        date.set(Calendar.YEAR, year);
        date.set(Calendar.MONTH, month);
        date.set(Calendar.DATE, dayNumber);
        this.entries = EntryController.LoadEntries(date);
    }

    public int getDateNumber() {
        return dayNumber;
    }
   
    public int getMonth() {
        return month;
    }

    public int getYear() {
        return year;
    }
    public DayType getDateType() {
        return dayType;
    }

    // by Can
    public boolean isToday() {
        Calendar today = Calendar.getInstance();
        if (this.dayNumber == today.get(Calendar.DAY_OF_MONTH)
                && this.month == today.get(Calendar.MONTH)
                && this.year == today.get(Calendar.YEAR)) {
            return true;
        }
        return false;
    }

    public ArrayList<Entry> getEntries() {
        ArrayList<Entry> displayedEntries = new ArrayList<Entry>();
        for (Entry entry : entries) {
            if (!categoriesFilter.contains(entry.getCategory())) {
                continue;
            }
            if (!prioritiesFilter.contains(entry.getPriority())) {
                continue;
            }
            displayedEntries.add(entry);
        }
        return displayedEntries;
    }

    public void setCategoriesFilter(List<String> categories) {
        this.categoriesFilter = categories;
    }

    public void setPrioritiesFilter(ArrayList<String> priorities) {
        this.prioritiesFilter = priorities;
    }
}
